@extends('frontend/layouts/default')
@section('title')
Đăng bài giảng mới
@stop
@section('content')
<h3 style="text-align: center">
    <span class="glyphicon glyphicon-pencil"></span> {{ !empty($data['lesson']->id)?"Chỉnh sửa bài viết" : "Thêm bài viết
    mới" }}
</h3>
@if(Session::has('success'))
<h3>
    {{Session::get('success')}}
</h3>
@endif
<form class="form-horizontal" action="" method="post" role="form">
    <?= Form::token() ?>
    <input type="hidden" name="data[Lesson][id]" id="data[Lesson][id]" value="<?= $data['lesson']->id ?>"/>

    <div class="row">
        <div class="col-md-9">
            <div class="form-group <?= $errors->has('title') ? 'error' : '' ?>">
                <label class="control-label col-sm-4">Tiêu đề</label>

                <div class="col-sm-8">
                    <input type="text" name="data[Lesson][title]" id="data[Lesson][title]" class="form-control"
                           value="<?= $data['lesson']->title ?>"/>
                    <?= $errors->first('title', '<span class="help-inline">:message</span>') ?>
                </div>

            </div>

            <div class="form-group <?= $errors->has('embed') ? 'error' : '' ?>">
                <label class="control-label col-sm-4">Mã Youtube</label>

                <div class="col-sm-8">
                    <span>
                        http://www.youtube.com/watch?v=<b style="color: red;">xxMr4OfWNT0</b>
                    </span>
                    <input type="text" name="data[Lesson][youtube]" id="data[Lesson][youtube]"
                           class="form-control" value="<?= $data['lesson']->youtube ?>"/>

                    <?= $errors->first('embed', '<span class="help-inline">:message</span>') ?>
                </div>

            </div>
            @if(!empty($data['lesson']->youtube))
            <div class="form-group <?= $errors->has('embed') ? 'error' : '' ?>">
                <label class="control-label col-sm-4">Preview Video</label>

                <div class="col-sm-8">
                    <iframe width="560" height="315" src="//www.youtube.com/embed/<?= $data['lesson']->youtube ?>"
                            frameborder="0" allowfullscreen></iframe>
                </div>
            </div>
            @endif
            <div class="form-group <?= $errors->has('content') ? 'error' : '' ?>">
                <label class="control-label col-sm-4">Nội dung</label>

                <div class="col-sm-8">
                    <textarea name="data[Lesson][content]" id="textareabox" class="form-control"
                              rows="25"><?= $data['lesson']->content ?>
                    </textarea>
                    <?= $errors->first('content', '<span class="help-inline">:message</span>') ?>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-4">
                    Tags
                </label>

                <div class="col-sm-8">
                    <span> Các tag được cách nhau bằng dấu (<font color="red">,</font>)</span>
                    <input name="data[Tags]" id="data[Tags]" class="form-control"/>
                    @if(isset($data['tags']))
                    @foreach($data['tags'] as $tag)
                    <a href="javascript:void(0)" class="btn btn-danger btn-xs">{{$tag->title}}</a>&nbsp;
                    @endforeach
                    @endif
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-4">
                    Tab
                </label>

                <div class="col-sm-8">
                    <textarea class="form-control" name="data[Lesson][tab]"
                              rows="15"><?= $data['lesson']->tab ?></textarea>
                </div>
            </div>
            @if(Sentry::getUser()->hasAnyAccess(['lesson','lesson.approve']))
            <div class="form-group">
                <label class="control-label col-sm-4">Trạng thái</label>

                <div class="col-sm-8">
                    <?= Form::Select('data[Lesson][status]', Config::get('constants.TEXT_STATUS'), Input::old('data[Lesson][status]', $data['lesson']->status), array('class' => 'form-control')) ?>
                </div>
            </div>
            @endif
        </div>
        <div class="col-md-3 colright">
            <div>
                <div class="panel panel-default">
                    <div class="panel-heading">Ảnh đại diện</div>
                    <div class="panel-body" align="center">

                    </div>
                </div>
            </div>
            <div>
                <div class="panel panel-default">
                    <div class="panel-heading">Điệu</div>
                    <div class="panel-body" align="center">
                        <?= Form::Select('data[Lesson][tone_id]', $data['tones'], Input::old('data[Lesson][tone_id]', $data['lesson']->tone_id), array('class' => 'form-control')) ?>
                    </div>
                </div>
            </div>
            <div>
                <div class="panel panel-default">
                    <div class="panel-heading">Chuyên mục</div>
                    <div class="panel-body" align="center">
                        <?= Form::Select('data[Lesson][category_id]', $data['categories'], Input::old('data[Lesson][category_id]', $data['lesson']->category_id), array('class' => 'form-control')) ?>
                    </div>

                    <div class="panel-heading">Trình độ</div>
                    <div class="panel-body" align="center">
                        <select name="data[Lesson][level]" class="form-control">
                            <option value="0">Chưa xếp hạng</option>
                            @for($i = 1; $i <=10;$i++)
                            <option value="<?= $i ?>" <?= ($i == $data['lesson']->level) ? "selected" : "" ?>>
                                Level <?= $i ?>
                            </option>
                            @endfor
                        </select>
                    </div>
                </div>

            </div>
            <div>
                <div class="panel-default panel">
                    <div class="panel-heading">Chủ đề</div>
                    <div class="panel-body" align="center">
                        {{Form::select('data[Topics][]',$data['topics'],array(),array('multiple'=>'multiple','class'=>'form-control','size'=>8))}}
                    </div>
                </div>
            </div>
            <div class="controls pull-right">
                <a class="btn btn-link" href="{{ route('bai-giang') }}">Hủy</a>
                <button type="submit" class="btn btn-success btn-sm"><span
                        class="glyphicon glyphicon-floppy-disk"></span> Lưu lại
                </button>
            </div>
        </div>
    </div>
</form>
<script src="{{asset('assets/commons/js/ckeditor/ckeditor.js')}}" type="text/javascript"></script>
<script type="text/javascript">
    CKEDITOR.replace('textareabox', {toolbar: 'CusToolbar', height: '500px'});
</script>
@stop